const express = require('express')

const app = express()



app.use(express.static('public'));

app.get('/get', (req, res) => {
    res.send('hello,GET')
})
app.post('/post', (req, res) => {
    res.send('hello,post')
})
app.post('/xml', (req, res) => {
    res.send('ok')
})
app.get('/xml', (req, res) => {
    //响应头
    res.setHeader('Content-Type', 'text/xml')
    //返回xml的格式
    res.send('<?xml version="1.0" encoding="UTF-8" ?><book><name>三国演义</name><about>罗贯中</about></book>')
})
app.post('/json', (req, res) => {
    res.send('ok');
})
app.get('/json', (req, res) => {
    var data = {
        name: '红楼梦',
        author: '曹雪芹'
    };
    res.send(data);
})
app.listen(3000, () => {
    console.log('http://127.0.0.1:3000');
})

// npm init -y
// npm i -S express